﻿using HCQ2WebAPI_Logic.BaseAPIController;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web.Http;
using HCQ2_Model.ViewModel.WebAPI;
using HCQ2WebAPI_Logic.Model;
using HCQ2_Common.Constant;
using HCQ2_Model.DocModel.APIModel;
using HCQ2_Model.ViewModel;
using HCQ2_Model;
using HCQ2_Model.DocModel;
using System;
using HCQ2_Common.Encrypt;
using HCQ2_Model.BaneUser.APP.Params;
using System.Web;
using HCQ2_Model.DocModel.APIResultModel;
using HCQ2_Model.VR.Params;
using HCQ2_Model.VR.Model;
using System.IO;
using HCQ2_Common;
using HCQ2_Model.VRDD.InputDto._0602;
using HCQ2_Model.VRDD.OutputDto._0602;
using HCQ2_Model.VRDD.OutputDto._0730;
using HCQ2_Model.VRDD.InputDto._0730;
using HCQ2_Model.VRDD.InputDto._210908;
using HCQ2_Model.VRDD.OutputDto._210908;
using HCQ2_Model.VRDD.InputDto._211026;
using HCQ2_Model.APIBase;

namespace HCQ2WebAPI_Logic.DocumentController
{
    /// <summary>
    ///  VR客户端商城相关接口
    /// </summary>
    public class VRClientAPIController: BaseWeiXinApiLogic
    {
        //****************************************************1.0 用户管理*******************************************************
        /// <summary>
        ///  获取用户点赞、关注用户信息
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel CheckUserFocus(FocusUserModel model)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            Dictionary<string, bool> map = new Dictionary<string, bool>();
            //是否关注
            map.Add("be_focus", operateContext.bllSession.T_VLineAttentionUser.SelectCount(s => s.user_guid.Equals(model.userid) && s.by_guid.Equals(model.be_userid)) > 0);
            //是否点赞
            map.Add("be_star", operateContext.bllSession.T_VLineUserUserStar.SelectCount(s => s.user_guid.Equals(model.userid) && s.star_guid.Equals(model.be_userid)) > 0);
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "", map);
        }

        #region 1.0 获取用户信息 + WebApiResultJsonModel GetUserData(EmpowerTree model)
        /// <summary>
        ///  获取用户信息
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel GetUserData(EmpowerTree model)
        {
            if(string.IsNullOrEmpty(model.userid) && model.create_id<=0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "userid、create_id不能同时为空！", null);
            T_User user;
            if (!string.IsNullOrEmpty(model.userid))
                user = operateContext.bllSession.T_User.FindSingle(s => s.user_guid.Equals(model.userid));
            else
                user = operateContext.bllSession.T_User.FindSingle(s => s.user_id == model.create_id);
            if (user==null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前用户不存在~", null);
            VRModifyUserModel result = new VRModifyUserModel
            {
                use_type = user.use_type,
                focus_num = user.focus_num,
                fans_num = user.fans_num,
                mark_star_num = user.mark_star_num,
                work_num = operateContext.bllSession.T_DocumentInfo.SelectCount(s => s.create_id == user.user_id && s.page_type.Equals("VRWorks") && !s.if_remove),
                manager_num = operateContext.bllSession.T_DocumentInfo.SelectCount(s => s.create_id == user.user_id && s.page_type.Equals("VRManager") && !s.if_remove),
                user_address = user.user_address,
                user_note = user.user_note,
                user_unit = user.user_unit,
                unit_code = user.unit_code,
                buy_gold = user.buy_gold,
                give_gold = user.give_gold,
                user_name = user.user_name,
                loginName = user.login_name,
                userSex = user.user_sex,
                userIdentify = user.user_identify,
                cellPhone = user.user_phone,
                userid = user.user_guid,
                email = user.user_email,
                headUrl = (!string.IsNullOrEmpty(user.user_img) && user.user_img.IndexOf("http")<0) ? user.user_img.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/"))) : user.user_img
            };
            EmpowerTree p = new EmpowerTree
            {
                groupName=model.groupName,
                dataFormat="list",
                treeScope=0,
                proType=2,
                userid=model.userid
            };
            List<VRClientTreeModel> list = operateContext.bllSession.T_DocumentFolder.GetDocTreeAPIData(p, user.user_id);
            if(list!=null)
                result.course_num = list.Count;
            //拥有角色
            result.haveRole = operateContext.bllSession.T_Role.getUserRole(user.user_id);
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "获取个人信息成功~", result);   
        }
        #endregion

        #region 1.1 更新用户信息 + WebApiResultJsonModel BbsModifyUser(ModifyUserInfoMessage model)
        /// <summary>
        ///  更新用户信息
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel BbsModifyUser(ModifyUserInfoMessage model)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            if (!string.IsNullOrEmpty(model.loginName))
            {
                //判断登录名是否被占用
                int count = operateContext.bllSession.T_User.SelectCount(s => s.login_name.Equals(model.loginName, StringComparison.CurrentCultureIgnoreCase) && !s.user_guid.Equals(model.userid));
                if (count > 0)
                    return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "修改的登录名已被占用~", null);
            }
            //构建对象
            T_User user = new T_User
            {
                login_name = model.loginName,
                user_sex = model.userSex,
                user_identify = model.userIdentify,
                user_phone = model.cellPhone,
                user_email = model.email,
                user_address = model.user_address,
                user_note = model.user_note,
                user_name = model.user_name
            };
            List<string> list = new List<string>() { "user_identify", "user_phone", "user_email", "user_address", "user_note" };
            if (!string.IsNullOrEmpty(model.loginName))
                list.Add("login_name");
            if (!string.IsNullOrEmpty(model.userSex))
                list.Add("user_sex");
            if (!string.IsNullOrEmpty(model.user_name))
                list.Add("user_name");
            int mark = operateContext.bllSession.T_User.Modify(user, s => s.user_guid.Equals(model.userid), list.ToArray());
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "修改个人信息成功~", null);
        }
        #endregion

        #region 1.2 修改密码 + WebApiResultJsonModel BbsModifyPassword(EmpowerTree model)
        /// <summary>
        ///  修改密码
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel BbsModifyPassword(ModifyPassword model)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            //验证旧密码是否正确
            int count = operateContext.bllSession.T_User.SelectCount(s => s.user_pwd.Equals(EncryptHelper.Md5Encryption(model.oldPassword)) && s.user_guid.Equals(model.userid));
            if (count <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "密码错误~", null);
            int mark = operateContext.bllSession.T_User.Modify(new T_User { user_pwd = EncryptHelper.Md5Encryption(model.newPassword) }, s => s.user_guid.Equals(model.userid), "user_pwd");
            if (mark <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Error, "密码修改失败~", null);
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "密码修改成功~", null);
        }
        #endregion

        #region 1.3 判断当前机器是否授权 + WebApiResultJsonModel BbsAccredit(UseVrModel model)
        /// <summary>
        ///  判断当前机器是否授权
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel BbsAccredit(UseVrModel model)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), "");
            int user_id = HCQ2UI_Helper.Session.SysPermissSession.ChangeIdByGuid(model.userid);
            //1.1 判断是否授权
            List<T_DocEmpower> list = operateContext.bllSession.T_DocEmpower.Select(s => s.user_id.Equals(user_id) && s.status == 1 && s.start_date <= DateTime.Now && s.end_date >= DateTime.Now);
            if (list==null || list.Count<=0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "尚未授权~", "0");
            //1.2 判断是否绑定机器码
            List<T_DocEmpower> tempList = list.Where(s => s.machine_code.Equals(model.machine_code)).ToList();
            if (tempList==null || tempList.Count<=0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前机器码绑定过期或尚未绑定~", "1");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "已授权并且当前机器码已成功绑定~", "2");
        }
        #endregion

        //****************************************************2.0 商城管理*******************************************************
        #region 获取目录路径列表 + WebApiResultJsonModel GetFolderPathList(DocLevelTreeParam model)
        /// <summary>
        ///  获取目录路径列表
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        [HCQ2_Common.Attributes.SkipApi]
        public WebApiResultJsonModel<List<DocLevelTree>> GetFolderPathList(DocLevelTreeParam model)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel<List<DocLevelTree>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            var list = operateContext.bllSession.T_DocumentFolder.GetFolderPathList(model);
            return ApiResultJsonModel<List<DocLevelTree>>.RedirectWebApi(WebResultCode.Ok, "获取目录路径列表成功~", list);
        }
        #endregion

        #region 2.0.1 获取【素材】商城素材/作品列表树 + WebApiResultJsonModel GetVRManagerTreeData(EmpowerTree model)
        /// <summary>
        ///  素材导航树
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        [HCQ2_Common.Attributes.SkipApi]
        public WebApiResultJsonModel<List<VRClientTreeModel>> GetVRManagerTreeData(EmpowerTree model)
        {
            model.treeType = "VRManager";
            return GetEmPowerTreeData(model);
        }
        #endregion

        #region 2.0.2 获取【作品】商城素材/作品列表树 + WebApiResultJsonModel GetVRWorksTreeData(EmpowerTree model)
        /// <summary>
        ///  作品导航树
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        [HCQ2_Common.Attributes.SkipApi]
        public WebApiResultJsonModel<List<VRClientTreeModel>> GetVRWorksTreeData(EmpowerTree model)
        {
            model.treeType = "VRWorks";
            return GetEmPowerTreeData(model);
        }
        #endregion

        #region 2.0.3 获取【组件】商城素材/作品列表树 + WebApiResultJsonModel GetVRModuleTreeData(EmpowerTree model)
        /// <summary>
        ///  组件导航树
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        [HCQ2_Common.Attributes.SkipApi]
        public WebApiResultJsonModel<List<VRClientTreeModel>> GetVRModuleTreeData(EmpowerTree model)
        {
            model.treeType = "VRModule";
            return GetEmPowerTreeData(model);
        }
        #endregion

        #region 2.0.4 获取【度度圈】商城素材/作品列表树 + WebApiResultJsonModel GetDDCircleTreeData(EmpowerTree model)
        /// <summary>
        ///  度度圈导航树
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        [HCQ2_Common.Attributes.SkipApi]
        public WebApiResultJsonModel<List<VRClientTreeModel>> GetDDCircleTreeData(EmpowerTree model)
        {
            model.treeType = "DDCircle";
            return GetEmPowerTreeData(model);
        }
        #endregion

        #region 2.0.5 获取【奇点元宇宙】目录导航 + WebApiResultJsonModel GetQDMetaTreeData(EmpowerTree model)
        /// <summary>
        ///  获取【奇点元宇宙】目录导航
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        [HCQ2_Common.Attributes.SkipApi]
        public WebApiResultJsonModel<List<VRClientTreeModel>> GetQDMetaTreeData(EmpowerTree model)
        {
            model.treeType = "QDMeta";
            return GetEmPowerTreeData(model);
        }
        #endregion

        #region 2.0.6 获取【奇点元宇宙】素材目录导航 + WebApiResultJsonModel GetQDMaterialTreeData(EmpowerTree model)
        /// <summary>
        ///  获取【奇点元宇宙】素材目录导航
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        [HCQ2_Common.Attributes.SkipApi]
        public WebApiResultJsonModel<List<QDClientTreeModel>> GetQDMaterialTreeData(QDMaterialTree model)
        {
            model.treeType = "QDMaterial";
            var param = Helper.AutoMapperConvert<EmpowerTree,QDMaterialTree>(model);
            param.limitType = false;
            List<QDClientTreeModel> result = new List<QDClientTreeModel>();
            var list = GetEmPowerTreeData(param);
            list.value?.ForEach(s => result.Add(Helper.AutoMapperConvert<QDClientTreeModel, VRClientTreeModel>(s)));
            return ApiResultJsonModel<List<QDClientTreeModel>>.RedirectWebApi(WebResultCode.Ok, "获取素材目录导航成功~", result);
        }
        #endregion

        #region 2.0 获取导航树 + WebApiResultJsonModel GetEmPowerTreeData(EmpowerTree model)
        /// <summary>
        ///  获取导航树
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [HCQ2_Common.Attributes.SkipApi]
        public WebApiResultJsonModel<List<VRClientTreeModel>> GetEmPowerTreeData(EmpowerTree model)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel<List<VRClientTreeModel>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            //必填项验证
            if (string.IsNullOrEmpty(model.treeType) && string.IsNullOrEmpty(model.folder_path))
                return ApiResultJsonModel<List<VRClientTreeModel>>.RedirectWebApi(WebResultCode.Exception, "目录树类别和folder_path不允许同时为空！", null);
            int user_id = 0;
            if (!string.IsNullOrEmpty(model.userid))
            {
                user_id = HCQ2UI_Helper.Session.SysPermissSession.ChangeIdByGuid(model.userid);
                model.user = user_id;
            }
            if(model.favorite>-1 && string.IsNullOrEmpty(model.userid))
                return ApiResultJsonModel<List<VRClientTreeModel>>.RedirectWebApi(WebResultCode.Exception, "获取收藏列表必须传递userid参数！", null);
            List<VRClientTreeModel> list = operateContext.bllSession.T_DocumentFolder.GetDocTreeAPIData(model, user_id);
            return ApiResultJsonModel<List<VRClientTreeModel>>.RedirectWebApi(WebResultCode.Ok, "获取授权列表成功~", list);
        }
        #endregion

        #region 2.0.0  获取导航树相关数据统计 + WebApiResultJsonModel GetTreeDataStatistics(EmpowerTree model)
        /// <summary>
        ///  获取导航树相关数据统计
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [HCQ2_Common.Attributes.SkipApi]
        public WebApiResultJsonModel GetTreeDataStatistics(EmpowerTree model)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            //必填项验证
            if (string.IsNullOrEmpty(model.treeType) && string.IsNullOrEmpty(model.folder_path))
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "目录树类别和folder_path不允许同时为空！", null);
            int user_id = 0;
            if (!string.IsNullOrEmpty(model.userid))
                user_id = HCQ2UI_Helper.Session.SysPermissSession.ChangeIdByGuid(model.userid);
            List<TreeDataStatisticsNode> list = operateContext.bllSession.T_DocumentFolder.GetTreeStatistics(model, user_id);
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "成功获取授权列表数据统计~", list);
        }
        #endregion

        #region 2.1 获取商品列表【原始】 + WebApiResultJsonModel ShowView(ViewGoodsModel model)
        /// <summary>
        ///  获取商品列表
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        [HCQ2_Common.Attributes.SkipApi]
        public WebApiResultJsonModel ShowView(ViewGoodsModel model)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            TableModel result = operateContext.bllSession.T_DocumentInfo.GetAPPShopList(model, HCQ2UI_Helper.Session.SysPermissSession.ChangeIdByGuid(model.userid));
            if (result == null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Error, "获取商品列表失败~", "");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "获取商品列表成功~", result);
        }
        #endregion

        #region 2.1-1 获取素材商品列表 + WebApiResultJsonModel ShowVRManagerView(ViewGoodsModel model)
        /// <summary>
        ///  获取素材商品列表
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        [HCQ2_Common.Attributes.SkipApi]
        public WebApiResultJsonModel ShowVRManagerView(ViewGoodsModel model)
        {
            model.vrType = 0;
            return ShowView(model);
        }
        #endregion

        #region 2.1-2 获取作品商品列表 + WebApiResultJsonModel ShowVRWorksView(ViewGoodsModel model)
        /// <summary>
        ///  获取作品商品列表
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        [HCQ2_Common.Attributes.SkipApi]
        public WebApiResultJsonModel ShowVRWorksView(ViewGoodsModel model)
        {
            model.vrType = 1;
            //10：关注；11：赞过
            if((model.goodsType==10 || model.goodsType==11) && string.IsNullOrEmpty(model.userid))
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "获取关注、点赞作品列表时必须传递用户id~", "");
            return ShowView(model);
        }
        #endregion

        #region 2.1-3 获取组件商品列表 + WebApiResultJsonModel ShowVRModuleView(ViewGoodsModel model)
        /// <summary>
        ///  获取组件商品列表
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        [HCQ2_Common.Attributes.SkipApi]
        public WebApiResultJsonModel ShowVRModuleView(ViewGoodsModel model)
        {
            model.vrType = 2;
            return ShowView(model);
        }
        #endregion

        #region 2.1.1 获取商品详情 + WebApiResultJsonModel GetGoodDetail(GoodDetialModel model)
        /// <summary>
        ///  获取商品详情
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        /// <remarks>
        /// 1、需求变更： 禅道id：234 日期：【2021-11-21】<br/>
        /// 2、需求变更： 禅道id：252 日期：【2022-01-15】<br/>
        /// </remarks>
        [HttpPost]
        [HCQ2_Common.Attributes.SkipApi]
        public WebApiResultJsonModel<GoodsDetal> GetGoodDetail(GoodDetialModel model)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel<GoodsDetal>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            //判断参数
            if(model.file_id<=0 && string.IsNullOrEmpty(model.file_code))
                return ApiResultJsonModel<GoodsDetal>.RedirectWebApi(WebResultCode.Exception, "作品id和代码不允许同时为空！", null);
            if (model.file_id <= 0)
            {
                var file = operateContext.bllSession.T_DocumentInfo.FindSingle(s => s.file_code.Equals(model.file_code) && s.file_status == 5);
                if(file==null)
                    return ApiResultJsonModel<GoodsDetal>.RedirectWebApi(WebResultCode.Exception, "当前代码后台不存在或已下架！", null);
                model.file_id = file.file_id;
            }
            //1.0 验证商品id
            int mark = operateContext.bllSession.T_DocumentInfo.SelectCount(s => s.file_id == model.file_id);
            if (mark<=0)
                return ApiResultJsonModel<GoodsDetal>.RedirectWebApi(WebResultCode.Exception, "当前商品信息在后台中不存在，请核实~", null);
            int user_id = string.IsNullOrEmpty(model.userid) ? 0 : HCQ2UI_Helper.Session.SysPermissSession.ChangeIdByGuid(model.userid);
            GoodsDetal result = operateContext.bllSession.T_DocumentInfo.GetAppGoodsDetail(model.file_id, user_id);
            if (result == null)
                return ApiResultJsonModel<GoodsDetal>.RedirectWebApi(WebResultCode.Error, "商品详情数据异常~", null);
            return ApiResultJsonModel<GoodsDetal>.RedirectWebApi(WebResultCode.Ok, "成功获取商品详情~", result);
        }
        #endregion
         
        #region 2.2 获取商品缩略图地址 + WebApiResultJsonModel ShowViewID(ViewFileIMG model)
        /// <summary>
        ///  获取商品缩略图地址
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        [HCQ2_Common.Attributes.SkipApi]
        public WebApiResultJsonModel ShowViewID(ViewFileIMG model)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            List<T_DocBagFileRecord> list = operateContext.bllSession.T_DocBagFileRecord.Select(s => s.file_id == model.file_id);
            if (list == null || list.Count <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前商品并未上传缩略图~", "");
            List<Dictionary<string, object>> urlList = new List<Dictionary<string, object>>();
            foreach (T_DocBagFileRecord item in list)
            {
                Dictionary<string, object> temp = new Dictionary<string, object>();
                temp.Add("bag_id", item.bag_id);
                temp.Add("file_type",item.file_type);//缩略图展示类别
                temp.Add("file_name", item.file_name);
                temp.Add("file_url", item.file_url.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/"))));
                urlList.Add(temp);
            }
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "获取商品缩略图成功~", urlList);
        }
        #endregion 

        #region 2.3 判断商品是否可用 + WebApiResultJsonModel VerifyUseById(GoodDetialModel model)
        /// <summary>
        ///  判断商品是否可用
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel VerifyUseById(GoodDetialModel model)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), "");
            if(string.IsNullOrEmpty(model.userid))
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "用户信息异常！", "");
            var file = operateContext.bllSession.T_DocumentInfo.FindSingle(s => s.file_id == model.file_id);
            if (model.file_id<=0 || file==null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "商品id信息异常！", "");
            int user_id = HCQ2UI_Helper.Session.SysPermissSession.ChangeIdByGuid(model.userid);
            List<int> ids = new List<int>();
            ids.Add(model.file_id);
            var mess = operateContext.bllSession.N_Order.CheckCommodityPay(ids, user_id);
            if(mess==null || mess.Count<=0)
                 return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "此商品尚未购买或已过期！", "");
            //获取购买结束日期
            string endTime = operateContext.bllSession.N_Order.GetPayEndTime(user_id, model.file_id);
            Dictionary<string, object> dict = new Dictionary<string, object>();
            dict.Add("file_name", file.file_name);
            dict.Add("file_code", file.file_code);
            dict.Add("file_status", file.file_status);
            dict.Add("allow_edit", file.allow_edit);
            dict.Add("EndTime",endTime);
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "", dict);
        }
        #endregion

        #region 2.4 获取最近目录 + WebApiResultJsonModel<OutputLatelyFloder> GetLatelyFloder(InputLatelyFloder param)
        /// <summary>
        ///  2.4 ✔获取最近目录
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<OutputLatelyFloder> GetLatelyFloder(InputLatelyFloder param)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel<OutputLatelyFloder>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            //判断目录是否存在
            var folder = operateContext.bllSession.T_DocumentFolder.FindSingle(s => s.folder_id == param.folder_id);
            if(folder==null)
                return ApiResultJsonModel<OutputLatelyFloder>.RedirectWebApi(WebResultCode.Exception,$"传递的目录id{param.folder_id}后台不存在！", null);
            OutputLatelyFloder result = new OutputLatelyFloder();
            //判断是否满足当前目录
            if (!string.IsNullOrEmpty(folder.group_name) && folder.group_name.Equals(param.group_name))
            {
                result.folder_id = folder.folder_id;
                result.folder_path = folder.folder_path;
                return ApiResultJsonModel<OutputLatelyFloder>.RedirectWebApi(WebResultCode.Ok, "成功获取最近目录~", result);
            }
            //获取父目录
            var f = operateContext.bllSession.T_DocumentFolder.FindSingle(s => s.folder_id == folder.folder_pid && s.group_name.Equals(param.group_name));
            if(f==null)
                return ApiResultJsonModel<OutputLatelyFloder>.RedirectWebApi(WebResultCode.Ok, "数据为空~", null);
            result = new OutputLatelyFloder { folder_id = f.folder_id, folder_path = f.folder_path };
            return ApiResultJsonModel<OutputLatelyFloder>.RedirectWebApi(WebResultCode.Ok, "成功获取最近目录~", result);
        }
        #endregion

        #region 2.5 ✔获取我收藏的商品列表 + WebApiResultJsonModel<OutputLatelyFloder> GetMyGoodsFromFavorite(InputMyGoods param)
        /// <summary>
        ///  2.5 ✔获取我收藏的商品列表
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<List<OutputMyGoods>> GetMyGoodsFromFavorite(InputMyGoods param)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel<List<OutputMyGoods>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int user_id = HCQ2UI_Helper.Session.SysPermissSession.ChangeIdByGuid(param.userid);
            if (user_id <= 0)
                return ApiResultJsonModel<List<OutputMyGoods>>.RedirectWebApi(WebResultCode.Exception, "用户内部编码参数异常！", null);
            var list = operateContext.bllSession.T_DocumentInfo.GetMyGoodsFavorite(param, user_id);
            return ApiResultJsonModel<List<OutputMyGoods>>.RedirectWebApi(WebResultCode.Ok, "成功获取我收藏的商品列表！", list);
        }
        #endregion

        //****************************************************2.0.1 目录树操作*****************************************************
        #region 2.0.1 添加普通目录树 + WebApiResultJsonModel AddVRTree(VRTreeModel param)
        /// <summary>
        ///  添加普通目录树
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel AddVRTree(VRTreeModel param)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            T_User user = operateContext.bllSession.T_User.FindSingle(s => s.user_guid.Equals(param.userid));
            if(user==null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception,"当前用户登录信息异常，请重新登录！", null);
            string picUrl = string.Empty;
            #region 添加目录
            T_DocumentFolder folder = new T_DocumentFolder
            {
                folder_name = param.folder_name,
                enLang = param.folder_ename,
                folder_pid = param.pid,
                group_name = param.group_name,
                is_share = param.is_share > 0 ? true : false,
                if_create_child = true,
                read_only = false,
                folder_order = param.folder_order,
                pro_type = param.pro_type,
                create_id = user.user_id,
                create_name = user.user_name,
                create_time = DateTime.Now,
                page_type = param.page_type,
                have_child = false,
                if_private = true,
                if_limit = true,
                folder_note = param.folder_note,
                rest_type = string.Empty,
                is_recommend = param.is_recommend > 0 ? true : false,
                langCode = Helper.GetGuid,
                update_name = user.user_name,
                update_date = DateTime.Now
            };
            int mark = operateContext.bllSession.T_DocumentFolder.Add(folder);
            if(mark<0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "数据添加失败！", null);
            if (folder.folder_pid>0)
                operateContext.bllSession.T_DocumentFolder.Modify(new T_DocumentFolder { have_child = true }, s => s.folder_id == folder.folder_pid, "have_child");
            #endregion

            #region  判断是否添加封面图标
            if (!string.IsNullOrEmpty(param.picFile))
            {
                //处理导航树封面图
                #region 1.0 处理上传文件夹
                string pathServer = "/uploadFile/FolderFile/" + user.user_guid + "/" + DateTime.Now.ToString("yyyyMMdd") + "/picture/";
                string uploadPath = request.MapPath(request.ApplicationPath + pathServer);
                if (!Directory.Exists(uploadPath))
                    Directory.CreateDirectory(uploadPath);
                #endregion

                #region 上传图片
                string picName = Guid.NewGuid().ToString().Replace("-", ""), prefixStr = param.picFile.Split(';')[0].ToString().Split('/')[1];
                byte[] picByte = Convert.FromBase64String(param.picFile.Split(',')[1]);
                string tempName = ImageHelper.CreateImageFromBytes(uploadPath, picName, picByte, prefixStr);
                picUrl = "~" + pathServer + picName + "." + prefixStr;
                if (!string.IsNullOrEmpty(tempName))
                    operateContext.bllSession.T_DocumentFolder.Modify(new T_DocumentFolder { folder_url = picUrl }, s => s.folder_id == folder.folder_id, "folder_url");
                #endregion
            }
            #endregion

            Dictionary<string, object> _folder = new Dictionary<string, object>();
            _folder.Add("folder_id", folder.folder_id);
            _folder.Add("picUrl", (!string.IsNullOrEmpty(picUrl)) ? picUrl.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/"))) : "");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "添加成功~", _folder);
        }
        #endregion

        #region 2.0.2 编辑普通目录树 + WebApiResultJsonModel ModifyVRTree(VRTreeModel param)
        /// <summary>
        ///  添加普通目录树
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel ModifyVRTree(VRTreeModel param)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            if(param.folder_id<=0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "修改目录树，【folder_id】属于必填项！", null);
            T_DocumentFolder result = operateContext.bllSession.T_DocumentFolder.FindSingle(s => s.folder_id == param.folder_id);
            if(result ==null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前编辑的目录树后台不存在！", null);
            T_User user = operateContext.bllSession.T_User.FindSingle(s => s.user_guid.Equals(param.userid));
            if (user == null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前用户登录信息异常，请重新登录！", null);
            #region 更新目录
            T_DocumentFolder folder = new T_DocumentFolder
            {
                folder_name = param.folder_name,
                enLang = param.folder_ename,
                group_name = param.group_name,
                is_share = param.is_share > 0 ? true : false,
                folder_order = param.folder_order,
                pro_type = param.pro_type,
                //page_type = param.page_type,
                folder_note = param.folder_note,
                is_recommend = param.is_recommend > 0 ? true : false,
                update_date = DateTime.Now,
                update_name = user.user_name
            };
            operateContext.bllSession.T_DocumentFolder.Modify(folder, s => s.folder_id == param.folder_id, "folder_name", "enLang", "group_name", "is_share", "folder_order", "pro_type", "folder_note", "is_recommend", "update_date", "update_name");
            #endregion
            //string picUrl = SaveTreePicture(new VRTreeModelPicture { folder_id = param.folder_id, picFile = param.picFile }, user, result.folder_url);
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "目录编辑成功~", "");
        }
        #endregion

        #region 2.0.3 编辑目录树图标 + WebApiResultJsonModel ModifyVRTreePicture(VRTreeModelPicture param)
        /// <summary>
        ///  编辑目录树图标
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel ModifyVRTreePicture(VRTreeModelPicture param)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            if (param.folder_id <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "修改目录树图标，【folder_id】属于必填项！", null);
            T_User user = operateContext.bllSession.T_User.FindSingle(s => s.user_guid.Equals(param.userid));
            if (user == null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前用户登录信息异常，请重新登录！", null);
            T_DocumentFolder result = operateContext.bllSession.T_DocumentFolder.FindSingle(s => s.folder_id == param.folder_id);
            if (result == null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前编辑的目录树后台不存在！", null);
            string picUrl = SaveTreePicture(param, user, result.folder_url);
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "目录树图标编辑成功~", picUrl);
        }
        #endregion

        #region 2.0.4 删除目录 + WebApiResultJsonModel DeleteVRTree(VRTreeModelPicture param)
        /// <summary>
        ///  删除目录
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel DeleteVRTree(VRTreeModelPicture param)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), "");
            if (param.folder_id <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "修改目录树图标，【folder_id】属于必填项！", "");
            T_User user = operateContext.bllSession.T_User.FindSingle(s => s.user_guid.Equals(param.userid));
            if(user==null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "请求的用户信息异常！", "");
            T_DocumentFolder result = operateContext.bllSession.T_DocumentFolder.FindSingle(s => s.folder_id == param.folder_id);
            if (result==null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前待删除的目录树后台不存在！", "");
            //1.0 是否属于不能删除节点
            if(result.if_sys)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前目录属于系统目录您不能删除！", "");
            //2.0 判断当前目录下是否有子目录
            int count = operateContext.bllSession.T_DocumentFolder.CheckIsChild(result.folder_path);
            if(count>0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前目录下存在子目录，请求被退回！", "");
            //3.0 判断目录下是否有课件作品
            count = operateContext.bllSession.T_DocumentFolder.CheckIsWorks(result.folder_id);
            if (count > 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前目录下存在未下架的课件，请求被退回！", "");
            //4.0 清理图标
            if (!string.IsNullOrEmpty(result.folder_url) && File.Exists(HttpContext.Current.Server.MapPath(result.folder_url)))
                File.Delete(HttpContext.Current.Server.MapPath(result.folder_url));
            //5.0 删除记录
            int mark = operateContext.bllSession.T_DocumentFolder.Delete(s => s.folder_id == param.folder_id);
            if(mark>0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "删除成功！", "");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "删除失败~", "");
        }
        #endregion

        #region 2.0.5 修改父目录 + WebApiResultJsonModel ModifyVRParentTree(VRParentTreeModel param)
        /// <summary>
        ///  修改父目录
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel ModifyVRParentTree(VRParentTreeModel param)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), "");
            if (param.folder_id <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "修改目录树结构，【folder_id】属于必填项！", "");
            T_DocumentFolder result = operateContext.bllSession.T_DocumentFolder.FindSingle(s => s.folder_id == param.folder_id);
            if(result==null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前待操作的目录树后台不存在！", "");
            int mark = operateContext.bllSession.T_DocumentFolder.CheckParentTree(result.folder_path, param.pid);
            if (mark>0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "不能将自己或自己的子目录设置成父目录！", "");
            if (param.pid > 0)
            {
                mark = operateContext.bllSession.T_DocumentFolder.SelectCount(s => s.folder_id == param.pid);
                if (mark <= 0)
                    return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, $"父目录【pid={param.pid}】在后台不存在！", "");
            }
            else
                param.pid = 0;
            operateContext.bllSession.T_DocumentFolder.Modify(new T_DocumentFolder { folder_pid = param.pid }, s => s.folder_id == param.folder_id, "folder_pid");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "目录结构调整成功！", "");
        }
        #endregion

        /// <summary>
        ///  上传图标
        /// </summary>
        /// <param name="param">参数</param>
        /// <param name="user">用户</param>
        /// <param name="folder_url">原始图标</param>
        private string SaveTreePicture(VRTreeModelPicture param,T_User user,string folder_url="")
        {
            //修改目录图标
            if (!string.IsNullOrEmpty(param.picFile))
            {
                //处理导航树封面图
                #region 1.0 处理上传文件夹
                string pathServer = "/uploadFile/FolderFile/" + user.user_guid + "/" + DateTime.Now.ToString("yyyyMMdd") + "/picture/";
                string uploadPath = request.MapPath(request.ApplicationPath + pathServer);
                if (!Directory.Exists(uploadPath))
                    Directory.CreateDirectory(uploadPath);
                #endregion

                #region 2.0上传图片
                string picName = Guid.NewGuid().ToString().Replace("-", ""), prefixStr = param.picFile.Split(';')[0].ToString().Split('/')[1];
                byte[] picByte = Convert.FromBase64String(param.picFile.Split(',')[1]);
                string tempName = ImageHelper.CreateImageFromBytes(uploadPath, picName, picByte, prefixStr),
                    _folderUrl = string.Empty;
                if (!string.IsNullOrEmpty(tempName))
                {
                    //2.1 删除原有图片
                    if (!string.IsNullOrEmpty(folder_url) && File.Exists(HttpContext.Current.Server.MapPath(folder_url)))
                        File.Delete(HttpContext.Current.Server.MapPath(folder_url));
                    _folderUrl = "~" + pathServer + picName + "." + prefixStr;
                    //2.2 更新链接
                    operateContext.bllSession.T_DocumentFolder.Modify(new T_DocumentFolder { folder_url = _folderUrl }, s => s.folder_id == param.folder_id, "folder_url");
                }
                #endregion
                _folderUrl = (!string.IsNullOrEmpty(_folderUrl)) ? _folderUrl.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/"))) : "";
                return _folderUrl;
            }
            else
            {
                //删除原来的图标
                if (!string.IsNullOrEmpty(folder_url) && File.Exists(HttpContext.Current.Server.MapPath(folder_url)))
                    File.Delete(HttpContext.Current.Server.MapPath(folder_url));
                operateContext.bllSession.T_DocumentFolder.Modify(new T_DocumentFolder { folder_url = "" }, s => s.folder_id == param.folder_id, "folder_url");
                return string.Empty;
            }
        }

        //****************************************************2.1 收藏目录*****************************************************
        #region 2.1.0 保存用户收藏关注目录 + WebApiResultJsonModel AddUserFolders(CollectFolderParam model)
        /// <summary>
        ///  保存用户收藏关注目录
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel AddUserFolders(CollectFolderParam model)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            var folder = operateContext.bllSession.T_DocumentFolder.FindSingle(o => o.folder_id == model.folder_id);
            if(folder == null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前导航目录不存在或已被删除~", "");
            int mark = operateContext.bllSession.T_VRUserFolder.SelectCount(o => o.user_guid.Equals(model.userid) && o.folder_id == model.folder_id);
            if (mark > 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "目录收藏成功~", folder.focus_num);
            T_VRUserFolder temp = new T_VRUserFolder { user_guid = model.userid, folder_pid = folder.folder_pid, folder_id = model.folder_id, folder_path = folder.folder_path, folder_date = DateTime.Now };
            mark = operateContext.bllSession.T_VRUserFolder.Add(temp);
            int focus_num = folder.focus_num + 1;
            if (mark > 0)
            {
                folder.focus_num = focus_num;
                operateContext.bllSession.T_DocumentFolder.Modify(folder, s => s.folder_id == model.folder_id, "focus_num");
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "目录收藏成功~", focus_num);
            }
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Error, "目录收藏失败~", "");
        }
        #endregion

        #region 2.1.1 移除用户收藏关注目录 + WebApiResultJsonModel RemoveUserFolderById(CollectFolderParam model)
        /// <summary>
        ///  移除用户收藏关注目录
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel RemoveUserFolderById(CollectFolderParam model)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            T_DocumentFolder folder = operateContext.bllSession.T_DocumentFolder.FindSingle(s => s.folder_id == model.folder_id);
            if(folder==null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "导航目录信息异常~", null);
            int mark = operateContext.bllSession.T_VRUserFolder.SelectCount(o => o.folder_id == model.folder_id && o.user_guid.Equals(model.userid));
            if (mark <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前用户并未收藏此目录~", folder.focus_num);
            mark = operateContext.bllSession.T_VRUserFolder.Delete(o => o.user_guid.Equals(model.userid) && o.folder_id == model.folder_id);
            if (mark > 0)
            {
                if (folder.focus_num > 0)
                {
                    folder.focus_num -= 1;
                    operateContext.bllSession.T_DocumentFolder.Modify(folder, s => s.folder_id == model.folder_id, "focus_num");
                }
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "目录已从收藏夹中移除成功~", folder.focus_num);
            }
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Error, "目录移除失败~", "");
        }
        #endregion

        #region 2.1.0-1 保存用户点赞目录 + WebApiResultJsonModel AddUserFolderStar(CollectFolderParam model)
        /// <summary>
        ///  保存用户点赞目录
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel AddUserFolderStar(CollectFolderParam model)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            var folder = operateContext.bllSession.T_DocumentFolder.FindSingle(o => o.folder_id == model.folder_id);
            if (folder == null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前导航目录不存在或已被删除~", "");
            int mark = operateContext.bllSession.T_VRUserFolderStar.SelectCount(o => o.user_guid.Equals(model.userid) && o.folder_id == model.folder_id);
            if (mark > 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "目录点赞成功~", folder.star_num);
            T_VRUserFolderStar temp = new T_VRUserFolderStar { user_guid = model.userid, folder_pid = folder.folder_pid, folder_id = model.folder_id, folder_path = folder.folder_path, folder_date = DateTime.Now };
            mark = operateContext.bllSession.T_VRUserFolderStar.Add(temp);
            int star_num = folder.star_num + 1;
            if (mark > 0)
            {
                folder.star_num = star_num;
                operateContext.bllSession.T_DocumentFolder.Modify(folder, s => s.folder_id == model.folder_id, "star_num");
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "目录点赞成功~", star_num);
            }
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Error, "目录点赞失败~", "");
        }
        #endregion

        #region 2.1.1-1 移除用户点赞目录 + WebApiResultJsonModel RemoveUserFolderStarById(CollectFolderParam model)
        /// <summary>
        ///  移除用户点赞目录
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel RemoveUserFolderStarById(CollectFolderParam model)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            T_DocumentFolder folder = operateContext.bllSession.T_DocumentFolder.FindSingle(s => s.folder_id == model.folder_id);
            if (folder == null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "导航目录信息异常~", null);
            int mark = operateContext.bllSession.T_VRUserFolderStar.SelectCount(o => o.folder_id == model.folder_id && o.user_guid.Equals(model.userid));
            if (mark <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前用户并未点赞此目录~", folder.star_num);
            mark = operateContext.bllSession.T_VRUserFolderStar.Delete(o => o.user_guid.Equals(model.userid) && o.folder_id == model.folder_id);
            if (mark > 0)
            {
                if (folder.star_num > 0)
                {
                    folder.star_num -= 1;
                    operateContext.bllSession.T_DocumentFolder.Modify(folder, s => s.folder_id == model.folder_id, "star_num");
                }
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "目录取消点赞成功~", folder.star_num);
            }
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Error, "目录取消点赞失败~", "");
        }
        #endregion

        #region 2.1.2 获取用户收藏目录列表 + WebApiResultJsonModel GetUserFolderByTreeType(CollectFolderList model)
        /// <summary>
        ///  获取用户收藏目录列表
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel GetUserFolderByTreeType(CollectFolderList model)
        {
            if (!ModelState.IsValid) 
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            List<CollectFolderResult> list = operateContext.bllSession.T_DocumentFolder.GetUserFolderCollectList(model);
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "成功获取已收藏列表~", list);
        }
        #endregion

        #region 2.1.3 获取目录详情 + WebApiResultJsonModel GetFolderDetail(FolderDetialModel model)
        /// <summary>
        ///  获取目录详情
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        /// <remarks>
        /// 1、需求变更： 禅道id：236 日期：【2021-11-23】<br/>
        /// 2、需求变更： 禅道id：280 日期：【2022-03-28】<br/>
        /// 3、需求变更： 禅道id：282 日期：【2022-04-04】<br/>
        /// </remarks>
        [HttpPost]
        [HCQ2_Common.Attributes.SkipApi]
        public WebApiResultJsonModel<ResultFolderDetials> GetFolderDetail(FolderDetialModel model)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel<ResultFolderDetials>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            //1.0 验证商品id
            var folder = operateContext.bllSession.T_DocumentFolder.FindSingle(s => s.folder_id == model.folder_id);
            if (folder == null)
                return ApiResultJsonModel<ResultFolderDetials>.RedirectWebApi(WebResultCode.Exception, "当前目录不存在或已被删除，请核实~", null);
            int user_id = string.IsNullOrEmpty(model.userid) ? 0 : HCQ2UI_Helper.Session.SysPermissSession.ChangeIdByGuid(model.userid);
            model.create_id = user_id;
            ResultFolderDetials result = operateContext.bllSession.T_DocumentFolder.GetFoldersDetail(model, folder.folder_path);
            if (result == null)
                return ApiResultJsonModel<ResultFolderDetials>.RedirectWebApi(WebResultCode.Error, "目录详情数据异常~", null);
            return ApiResultJsonModel<ResultFolderDetials>.RedirectWebApi(WebResultCode.Ok, "成功获取目录详情~", result);
        }
        #endregion

        #region 2.1.4-1 获取我的店铺（目录）列表 + WebApiResultJsonModel GetMyFolderList(MyFloderParam model)
        /// <summary>
        ///  2.1.4-1 获取我的店铺（目录）列表
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        /// <remarks>
        ///  1、禅道需求：id=264 【2022-02-21】<br/>
        /// </remarks>
        [HttpPost]
        public WebApiResultJsonModel<List<MyFloderModel>> GetMyFolderList(MyFloderParam param)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel<List<MyFloderModel>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int user_id = HCQ2UI_Helper.Session.SysPermissSession.ChangeIdByGuid(param.userid);
            var list = operateContext.bllSession.T_DocumentFolder.GetMyFloderList(param,user_id);
            return ApiResultJsonModel<List<MyFloderModel>>.RedirectWebApi(WebResultCode.Ok, "成功获取我的店铺列表~", list);
        }
        #endregion

        #region 2.1.4-2 获取所有店铺（目录）列表 + WebApiResultJsonModel GetAllFolderList(AllFloderParam model)
        /// <summary>
        ///  2.1.4-2 获取所有店铺（目录）列表
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        /// <remarks>
        ///  1、禅道需求：id=261 【2022-02-10】<br/>
        ///  2、禅道需求：id=264 【2022-02-21】<br/>
        /// </remarks>
        [HttpPost]
        public WebApiResultJsonModel<List<MyFloderModel>> GetAllFolderList(AllFloderParam param)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel<List<MyFloderModel>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int user_id = HCQ2UI_Helper.Session.SysPermissSession.ChangeIdByGuid(param.userid);
            var list = operateContext.bllSession.T_DocumentFolder.GetAllFloderList(param, user_id);
            return ApiResultJsonModel<List<MyFloderModel>>.RedirectWebApi(WebResultCode.Ok, "成功获取所有店铺列表~", list);
        }
        #endregion

        #region 2.1.5 获取我的课程（目录）列表 + WebApiResultJsonModel GetMyCourseList(MyCourseParam param)
        /// <summary>
        ///  2.1.5 获取我的课程（目录）列表
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<List<OutputMyCourse>> GetMyCourseList(MyCourseParam param)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel<List<OutputMyCourse>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int user_id = HCQ2UI_Helper.Session.SysPermissSession.ChangeIdByGuid(param.userid);
            var list = operateContext.bllSession.T_DocumentFolder.GetMyCourseList(param, user_id);
            return ApiResultJsonModel<List<OutputMyCourse>>.RedirectWebApi(WebResultCode.Ok, "成功获取我的课程列表~", list);
        }
        #endregion

        #region 2.1.6 获取用户收藏的商品和作品 + WebApiResultJsonModel GetUserFavorite(UserFavorite param)
        /// <summary>
        ///  2.1.6 获取用户收藏的商品和作品
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<List<OutputUserFavorite>> GetUserFavorite(UserFavorite param)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel<List<OutputUserFavorite>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int user_id = HCQ2UI_Helper.Session.SysPermissSession.ChangeIdByGuid(param.userid);
            var list = operateContext.bllSession.T_DocumentInfo.GetUserFavorite(param, user_id);
            return ApiResultJsonModel<List<OutputUserFavorite>>.RedirectWebApi(WebResultCode.Ok, "成功获取用户收藏的商品和作品~", list);
        }
        #endregion

        #region 2.1.7 获取店铺商品列表【抛弃】 + WebApiResultJsonModel GetGoodsByStoreList(InputGoodsByStore model)
        /// <summary>
        ///  2.1.7 获取店铺商品列表【抛弃】
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        /// <remarks>
        /// 用于购买用户在浏览店铺时展示的商品列表<br/>
        /// </remarks>
        [HttpPost]
        public WebApiResultJsonModel<List<OutputGoodsByStore>> GetGoodsByStoreList(InputGoodsByStore param)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel<List<OutputGoodsByStore>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int total,user_id = HCQ2UI_Helper.Session.SysPermissSession.ChangeIdByGuid(param.userid);
            var list = operateContext.bllSession.T_DocumentInfo.GetGoodsByStoreList(param, user_id,out total);
            return ApiResultJsonModel<List<OutputGoodsByStore>>.RedirectWebApi(WebResultCode.Ok, "成功获取店铺商品列表~", list);
        }
        #endregion

        #region 2.1.7 获取店铺商品列表【最新】 + WebApiResultJsonModel GetGoodsByStoreListCopy(InputGoodsByStore model)
        /// <summary>
        ///  2.1.7 获取店铺商品列表【最新】
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        /// <remarks>
        /// 用于购买用户在浏览店铺时展示的商品列表<br/>
        /// </remarks>
        [HttpPost]
        public WebApiResultJsonModel<BasePage<OutputGoodsByStore>> GetGoodsByStoreListCopy(InputGoodsByStore param)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel<BasePage<OutputGoodsByStore>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int total,user_id = HCQ2UI_Helper.Session.SysPermissSession.ChangeIdByGuid(param.userid);
            var list = operateContext.bllSession.T_DocumentInfo.GetGoodsByStoreList(param, user_id,out total);
            BasePage<OutputGoodsByStore> result = new BasePage<OutputGoodsByStore> { total = total, rows = list };
            return ApiResultJsonModel<BasePage<OutputGoodsByStore>>.RedirectWebApi(WebResultCode.Ok, "成功获取店铺商品列表~", result);
        }
        #endregion

        #region 2.18 设置商品是否已售馨 + WebApiResultJsonModel ModifyIsSoldOut(InputIsSoldOut model)
        /// <summary>
        ///  设置商品是否已售馨
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel ModifyIsSoldOut(InputIsSoldOut model)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int mark = operateContext.bllSession.T_DocumentInfo.SelectCount(s => s.file_id == model.fileId && s.file_status==5 && !s.if_remove);
            if(mark<=0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前商品已下架或已删除！", null);
            operateContext.bllSession.T_DocumentInfo.Modify(new T_DocumentInfo { isSoldOut = model.isSoldOut }, s => s.file_id == model.fileId, "isSoldOut");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "成功设置商品是否已售馨~", "");
        }
        #endregion

        #region 2.19 ✔设置商品是否店铺推荐 + WebApiResultJsonModel SetFileRecType(InputFileRecType param)
        /// <summary>
        ///  2.19 ✔ 设置商品是否店铺推荐 
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel SetFileRecType(InputFileRecType param)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int mark = operateContext.bllSession.T_DocumentInfo.SelectCount(s => s.file_id == param.FileID && s.file_status == 5 && !s.if_remove);
            if (mark <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前商品已下架或已删除！", null);
            operateContext.bllSession.T_DocumentInfo.Modify(new T_DocumentInfo { store_top = param.isStoreTop }, s => s.file_id == param.FileID, "store_top");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "成功设置商品是否店铺推荐~", "");
        }
        #endregion

        //****************************************************3.0 收藏夹管理*****************************************************
        #region 3.0 添加收藏夹【收藏作品】 + WebApiResultJsonModel AddFavoriteGoods(ViewFileIMG model)
        /// <summary>
        ///  添加收藏夹
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel AddFavoriteGoods(ViewFileIMG model)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int user_id = HCQ2UI_Helper.Session.SysPermissSession.ChangeIdByGuid(model.userid);
            //1.0 判断当前商品是否正常
            int count = operateContext.bllSession.T_DocumentInfo.SelectCount(s => s.file_id.Equals(model.file_id) && s.file_status.Equals(5));
            if(count<=0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前商品还未发布或者不存在~", "");
            int goodCount = operateContext.bllSession.T_VRFavoriteGoods.SelectCount(s => s.file_id.Equals(model.file_id) && s.user_id.Equals(user_id));
            if (goodCount > 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前商品已添加至收藏夹了~", "");
            int mark = operateContext.bllSession.T_VRFavoriteGoods.Add(new T_VRFavoriteGoods { file_id = model.file_id, user_id = user_id, create_date = DateTime.Now });
            if (mark<=0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Error, "商品添加收藏夹失败~", "");
            //2.0 累计收藏次数
            T_DocumentInfo info = operateContext.bllSession.T_DocumentInfo.Select(s => s.file_id.Equals(model.file_id)).FirstOrDefault();
            operateContext.bllSession.T_DocumentInfo.Modify(new T_DocumentInfo { hold_num = info.hold_num + 1 }, s => s.file_id.Equals(model.file_id), "hold_num");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "商品成功添加至收藏夹~", "");
        }
        #endregion

        #region 3.1 移出收藏夹 + WebApiResultJsonModel RemoveGoodsById(ViewGoodsModel model)
        /// <summary>
        ///  移出收藏夹
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel RemoveGoodsById(ViewFileIMG model)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int user_id = HCQ2UI_Helper.Session.SysPermissSession.ChangeIdByGuid(model.userid);
            int goodCount = operateContext.bllSession.T_VRFavoriteGoods.SelectCount(s => s.file_id.Equals(model.file_id) && s.user_id.Equals(user_id));
            if (goodCount <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, $"file_id:{model.file_id}当前商品不在收藏夹无需移出~", "");
            int mark = operateContext.bllSession.T_VRFavoriteGoods.Delete(s => s.file_id.Equals(model.file_id) && s.user_id.Equals(user_id));
            if (mark <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Error, "商品移出收藏夹失败~", "");
            //扣除收藏次数
            T_DocumentInfo info = operateContext.bllSession.T_DocumentInfo.Select(s => s.file_id.Equals(model.file_id)).FirstOrDefault();
            operateContext.bllSession.T_DocumentInfo.Modify(new T_DocumentInfo { hold_num = info.hold_num - 1 }, s => s.file_id.Equals(model.file_id), "hold_num");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "商品成功移出收藏夹~", "");
        }
        #endregion

        //****************************************************4.0 发布/下架******************************************************
        #region 4.0 商品下架处理 + WebApiResultJsonModel SoldOutGoodsById(ViewGoodsModel model)
        /// <summary>
        ///  商品下架处理
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel SoldOutGoodsById(ViewFileIMG model)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int user_id = HCQ2UI_Helper.Session.SysPermissSession.ChangeIdByGuid(model.userid);
            //查询自己上传的商品允许下架
            int count = operateContext.bllSession.T_DocumentFolderRelation.SelectCount(s => s.file_id.Equals(model.file_id));
            if(count<=0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前商品不存在~", "");
            int mark = operateContext.bllSession.T_DocumentInfo.Modify(new T_DocumentInfo { file_status = 4 }, s => s.file_id == model.file_id, "file_status");
            if (mark <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Error, "商品下架失败~", "");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "商品下架成功~", "");
        }
        #endregion

        #region 4.1 商品发布 + WebApiResultJsonModel IssueGoodsById(ViewGoodsModel model)
        /// <summary>
        ///  商品发布
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel IssueGoodsById(ViewFileIMG model)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int user_id = HCQ2UI_Helper.Session.SysPermissSession.ChangeIdByGuid(model.userid);
            //查询自己上传的商品允许发布
            int count = operateContext.bllSession.T_DocumentFolderRelation.SelectCount(s => s.file_id.Equals(model.file_id) && s.create_id.Equals(user_id));
            if (count <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "您没有权限发布当前商品~", "");
            //查看当前商品状态
            T_DocumentInfo file = operateContext.bllSession.T_DocumentInfo.Select(s => s.file_id.Equals(model.file_id)).FirstOrDefault();
            if(file==null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前商品不存在~", "");
            if(file.file_status==5)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "当前商品已发布至商城~", "");
            int mark = operateContext.bllSession.T_DocumentInfo.Modify(new T_DocumentInfo { file_status = 1 }, s => s.file_id == model.file_id, "file_status");
            if (mark <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Error, "商品发布失败~", "");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "商品发布成功等待管理员审核~", "");
        }
        #endregion

        //****************************************************5.0 增加数量******************************************************
        #region 5.0 累计引用次数 + WebApiResultJsonModel AddQuoteNumberById(ViewFileIMG model)
        /// <summary>
        ///  累计引用次数
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel AddQuoteNumberById(ViewFileIMG model)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            T_DocumentInfo file = operateContext.bllSession.T_DocumentInfo.Select(s => s.file_id.Equals(model.file_id) && s.file_status.Equals(5)).FirstOrDefault();
            if(file==null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前商品审核还未通过或者不存在，不能引用~", "");
            int mark = operateContext.bllSession.T_DocumentInfo.Modify(new T_DocumentInfo { quote_num = file.quote_num + 1 }, s => s.file_id.Equals(model.file_id), "quote_num");
            if (mark <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Error, "累计引用次数失败~", "");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "累计引用次数成功~", "");
        }
        #endregion

        #region 5.1 累计播放次数 + WebApiResultJsonModel AddPlayNumberById(ViewFileIMG model)
        /// <summary>
        ///  累计播放次数
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel AddPlayNumberById(ViewFileIMG model)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            T_DocumentInfo file = operateContext.bllSession.T_DocumentInfo.Select(s => s.file_id.Equals(model.file_id)).FirstOrDefault();
            if (file == null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前商品不存在~", "");
            int mark = operateContext.bllSession.T_DocumentInfo.Modify(new T_DocumentInfo { play_num = file.play_num + 1 }, s => s.file_id.Equals(model.file_id), "play_num");
            if (mark <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Error, "累计播放次数失败~", "");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "累计播放次数成功~", "");
        }
        #endregion

        #region 5.2 作品点赞+1 + WebApiResultJsonModel AddStar(VRStarView model)
        /// <summary>
        ///  点赞+1
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel AddStar(VRStarView model)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            T_User user = operateContext.bllSession.T_User.Select(s => s.user_guid.Equals(model.userid)).FirstOrDefault();
            int starCount = operateContext.bllSession.T_DocumentUserStar.SelectCount(s => s.create_id == user.user_id && s.file_id == model.file_id);
            if(starCount>0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "您已成功点赞~", "");
            starCount = operateContext.bllSession.T_DocumentUserStar.Add(new T_DocumentUserStar { create_id = user.user_id, create_name = user.user_name, file_id = model.file_id });
            if (starCount <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Error, "点赞失败~", "");
            T_DocumentInfo file = operateContext.bllSession.T_DocumentInfo.Select(s => s.file_id.Equals(model.file_id)).FirstOrDefault();
            operateContext.bllSession.T_DocumentInfo.Modify(new T_DocumentInfo { vr_star = file.vr_star + 1 }, s => s.file_id == model.file_id, "vr_star");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "点赞成功~", "");
        }
        #endregion

        #region 5.2 取消作品点赞 - 1 + WebApiResultJsonModel CancelStar(VRStarView model)
        /// <summary>
        ///  取消点赞 - 1
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel CancelStar(VRStarView model)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int userId = HCQ2UI_Helper.Session.SysPermissSession.ChangeIdByGuid(model.userid);
            int starCount= operateContext.bllSession.T_DocumentUserStar.SelectCount(s => s.create_id == userId && s.file_id == model.file_id);
            if(starCount<=0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "您并未对此商品点过赞~", "");
            starCount = operateContext.bllSession.T_DocumentUserStar.Delete(s => s.create_id == userId && s.file_id == model.file_id);
            if (starCount > 0)
            {
                T_DocumentInfo file = operateContext.bllSession.T_DocumentInfo.Select(s => s.file_id.Equals(model.file_id)).FirstOrDefault();
                int vrStar = file.vr_star - 1;
                if (vrStar <= 0)
                    vrStar = 0;
                operateContext.bllSession.T_DocumentInfo.Modify(new T_DocumentInfo { vr_star = vrStar }, s => s.file_id == model.file_id, "vr_star");
            }
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "取消点赞成功~", "");
        }
        #endregion
    }
}